package com.example.demo;

import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import javax.annotation.Resource;

@RestController
public class TestController {
    @Resource
    ReactiveMongoTemplate reactiveMongoTemplate;

    @GetMapping("/")
    public Flux<AudioUrl> test() {
        Criteria criteria0 = new Criteria();
        criteria0.and("markerId").is(6194);
        return getLabelListByCri(criteria0, "col_Vietnamese_20210425_1-mark-20210605");
    }

    public Flux<AudioUrl> getLabelListByCri(Criteria criteria, String colName) {
        return reactiveMongoTemplate.find(
                new Query(criteria).limit(1000), AudioUrl.class, colName);
    }
}
